package com.spider.admin.scaffold.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spider.admin.scaffold.entity.dto.DataDictionaryDTO;
import com.spider.admin.scaffold.entity.model.DataDictionary;
import com.spider.admin.scaffold.entity.model.DataDictionaryDesc;
import com.spider.admin.scaffold.entity.param.DataDictionaryQueryParam;
import com.spider.admin.scaffold.service.DataDictionaryService;
import com.spider.admin.scaffold.common.Result;
import com.spider.admin.scaffold.common.annotation.OperationAspect;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/23 8:15 下午
 */

@Tag(name = "数据字典接口")
@RequestMapping("/system/dataDictionary")
@RestController
public class DataDictionaryController {

    @Autowired
    private DataDictionaryService dataDictionaryService;

    @Operation(summary = "数据字典列表")
    @GetMapping
    public Result<Page<DataDictionary>> selectPage(DataDictionaryQueryParam queryParam) {
        return Result.of(dataDictionaryService.selectPage(queryParam));
    }

    @Operation(summary = "查看详情")
    @GetMapping("/{id}")
    public Result<DataDictionaryDTO> findById(@PathVariable Long id) {
        return Result.of(dataDictionaryService.findById(id));
    }

    @Operation(summary = "新增数据字典")
    @PostMapping
    @OperationAspect(accessPath = "/system/dataDictionary/save", accessDesc = "新增数据字典")
    public Result<DataDictionaryDTO> save(@RequestBody DataDictionaryDTO dictionaryDto) {
        return Result.of(dataDictionaryService.saveDataDictionary(dictionaryDto));
    }

    @Operation(summary = "修改数据字典")
    @PutMapping
    @OperationAspect(accessPath = "/system/dataDictionary/update", accessDesc = "新增数据字典")
    public Result<DataDictionaryDTO> update(@RequestBody DataDictionaryDTO dictionaryDto) {
        return Result.of(dataDictionaryService.updateDataDictionary(dictionaryDto));
    }

    @Operation(summary = "删除数据字典")
    @DeleteMapping("/delete")
    @OperationAspect(accessPath = "/system/dataDictionary/deleteById", accessDesc = "删除数据字典")
    public Result<Boolean> deleteById(@RequestParam("ids") String ids) {
        return Result.of(dataDictionaryService.deleteById(ids));
    }

    @Operation(summary = "新增数据字典-明细")
    @PostMapping("/createDictDesc")
    @OperationAspect(accessPath = "/system/dataDictionary/createDictDesc", accessDesc = "新增数据字典-明细")
    public Result<DataDictionaryDesc> createDictDesc(@RequestBody DataDictionaryDesc dictionaryDesc) {
        return Result.of(dataDictionaryService.createDictDesc(dictionaryDesc));
    }

    @Operation(summary = "修改数据字典-明细")
    @PutMapping("/updateDictDesc")
    @OperationAspect(accessPath = "/system/dataDictionary/updateDictDesc", accessDesc = "修改数据字典-明细")
    public Result<DataDictionaryDesc> updateDictDesc(@RequestBody DataDictionaryDesc dictionaryDesc) {
        return Result.of(dataDictionaryService.updateDictDesc(dictionaryDesc));
    }

    @Operation(summary = "删除数据字典-明细")
    @DeleteMapping("/deleteDictDesc/{id}")
    @OperationAspect(accessPath = "/system/dataDictionary/deleteDictDesc/deleteById", accessDesc = "删除数据字典")
    public Result<Boolean> deleteDictDesc(@PathVariable Long id) {
        return Result.of(dataDictionaryService.deleteDictDesc(id));
    }
}
